package com.woniuxy.searchassembly.controller;


import com.woniuxy.common.Result;
import com.woniuxy.hotel.api.SubwayPointAPI;
import com.woniuxy.hotel.form.SubwayForm;
import com.woniuxy.searchassembly.model.SubwayPoint;
import com.woniuxy.searchassembly.service.ISubwayPointService;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Kevin Kwok
 * @since 2021-05-24
 */
@Slf4j
@RestController
public class SubwayPointController implements SubwayPointAPI {

    @Resource
    private ISubwayPointService subwayPointService;

    @Override
    public Result querySubRoute(Integer routeNo) {
        List<String> sites = subwayPointService.queryByRouteNo(routeNo);
        return new Result(true,"查询成功",sites);
    }

    @Override
    public Result queryBySubSite(String routeName) {
        List<SubwayPoint> subwayPoint = subwayPointService.queryAllInfo(routeName);
        return new Result(true,"查询成功",subwayPoint);
    }

    @Override
    public Result addNewSites(SubwayForm subwayForm) {
        SubwayPoint subwayPoint = new SubwayPoint();
        BeanUtils.copyProperties(subwayForm,subwayPoint);
        int i = subwayPointService.addNewSites(subwayPoint);
        return new Result(true,"站点新增成功",i);
    }
}

